package com.all.learning.guava.other;

import java.util.Iterator;
import java.util.List;

import org.junit.Test;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;

public class GGfunction {

	@Test
	public void testFilter() {
		List<Integer> lists = Lists.newArrayList(15, 11, 1, 77, 33);
		Iterable<Integer> iterable = FluentIterable.from(lists).filter(new Predicate<Integer>() {
			@Override
			public boolean apply(Integer input) {
				return input >= 12;
			}
		});
		
		
		for (Iterator<Integer> it = iterable.iterator(); it.hasNext();) {
			Integer integer =  it.next();
			System.out.println(integer);
		}
		System.out.println("----------------");
		
		for (Integer integer : iterable) {
			System.out.println(integer);
		}

	}
	
	
	@Test
	public void testTransform() {
		List<Integer> lists = Lists.newArrayList(15, 11, 1, 77, 33);
		FluentIterable<String> fit = FluentIterable.from(lists).transform(new Function<Integer, String>() {
			@Override
			public String apply(Integer input) {
				return Joiner.on("#").join(input, "xx");
			}

		});
		
		System.out.println(fit.toString());
		
	}
}
